<template>
    <!-- @cancel="handleClose"  -->
    <BasicModal 
    v-bind="$attrs"  @cancel="handleClose" @register="registerModal" destroyOnClose :title="title" :showOkBtn="false" cancelText="关闭" width="80%" @ok="handleSubmit">
        <!-- <BasicForm @register="registerForm"/> -->
        <iframe  :src="iframUrl" frameborder="0" width="100%" height="600px" scrolling="auto" style="background-color: #fff;"></iframe>
    </BasicModal>
  </template>
  
  <script lang="ts" setup>
      import {ref, computed, unref} from 'vue';
      import {BasicModal, useModalInner} from '/@/components/Modal';
      import {BasicForm, useForm} from '/@/components/Form/index';
      import { useMessage } from '/@/hooks/web/useMessage';
      import {formSchema} from '../applyModelList.data';
      import {saveOrUpdate} from '../applyModelList.api';
      const { createConfirm } = useMessage();   
      // Emits声明
      const emit = defineEmits(['register','success']);
      const iframUrl=ref('');
      const isUpdate = ref(true);
      //表单配置
      const [registerForm, {setProps,resetFields, setFieldsValue, validate}] = useForm({
          //labelWidth: 150,
          schemas: formSchema,
          showActionButtonGroup: false,
          baseColProps: {span: 24}
      });
      //表单赋值
      const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => {
            iframUrl.value=data.record.url;
            // console.log(iframUrl.value,"122")
          //重置表单
        //   await resetFields();
        //   setModalProps({confirmLoading: false,showCancelBtn:!!data?.showFooter,showOkBtn:!!data?.showFooter});
        //   isUpdate.value = !!data?.isUpdate;
        //   if (unref(isUpdate)) {
        //       //表单赋值
        //       await setFieldsValue({
        //           ...data.record,
        //       });
        //   }
          // 隐藏底部时禁用整个表单
        //  setProps({ disabled: !data?.showFooter })
      });
      //设置标题
      const title = computed(() => (!unref(isUpdate) ? '新增' : '设计流程'));
      //表单提交事件 未使用
      async function handleSubmit(v) {
          try {
              let values = await validate();
              setModalProps({confirmLoading: true});
              //提交表单
              await saveOrUpdate(values, isUpdate.value);
              //关闭弹窗
              closeModal();
              //刷新列表
              emit('success');
          } finally {
              setModalProps({confirmLoading: false});
          }
      }
    function handleClose(){
        emit('success');
        // console.log('Cancel');
        // createConfirm({
        //   title: '关闭前请确认已保存修改?',
        //   content: '关闭后未保存的修改将丢失！',
        //   okText: '确认关闭',
        //   okType: 'danger',
        //   iconType: 'warning',
        //   onOk() {
        //     emit('success');
        //   },
        //   onCancel() {
        //     emit('success');
        //   },
        // });

      };
  </script>
  
  <style lang="less" scoped>
      /** 时间和数字输入框样式 */
    :deep(.ant-input-number){
          width: 100%
      }
  
      :deep(.ant-calendar-picker){
          width: 100%
      }
  </style>